# Template to evaluate common paths in different pipelines.
parameters:
  extraSubsets: ''

  # _* parameters are being used as a const array,
  # do not set them when using the template
  _const_paths:
    _wasm_specific_only: [
        eng/testing/bump-chrome-version.proj
        eng/testing/ChromeVersions.props
        eng/testing/WasmRunner*
        eng/testing/WasiRunner*
        eng/testing/scenarios/BuildWasiAppsJobsList.txt
        eng/testing/scenarios/BuildWasmAppsJobsList.txt
        eng/testing/tests.browser.targets
        eng/testing/tests.was*.targets
        eng/testing/was*provisioning.targets
        eng/testing/workloads-browser.targets
        eng/testing/workloads-testing.targets
        eng/testing/workloads-wasi.targets
        eng/testing/workloads-wasm.targets
        src/libraries/sendtohelix-browser.targets
        src/libraries/sendtohelix-wasi.targets
        src/libraries/sendtohelix-wasm.targets
        src/mono/mono/**/*wasm*
        src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/*
        src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/*
        src/mono/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/*
        src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/*
        src/mono/nuget/Microsoft.NETCore.BrowserDebugHost.Transport/*
        src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/**/*
        src/mono/nuget/Microsoft.NET.Workload*
        src/mono/sample/wasm/*
        src/mono/browser/*
        src/mono/wasi/*
        src/mono/wasm/*
        src/mono/mono/mini/interp/jiterpreter*
        src/tasks/WasmAppBuilder/*
        src/tasks/WasmBuildTasks/*
        src/tasks/WorkloadBuildTasks/*
        src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/*
        src/tasks/Microsoft.NET.WebAssembly.Webcil/*
        src/tests/Common/wasm-test-runner/*
    ]
    _wasm_pipelines: [
        eng/pipelines/**/*wasm*
    ]
    _wasm_src_native: [
        src/native/minipal/*
        src/native/libs/CMakeLists.txt
        src/native/libs/configure.cmake
        src/native/libs/build*
        src/native/libs/Common/*
        src/native/libs/System.Globalization.Native/*
        src/native/libs/System.IO.Compression.Native/*
        src/native/libs/System.Native/*
    ]
    _wasm_chrome: [
        eng/testing/bump-chrome-version.proj
        eng/testing/ChromeVersions.props
    ]
    _perf_pipeline_specific_only: [
        eng/pipelines/runtime-wasm-perf.yml
        eng/pipelines/coreclr/perf*.yml
        eng/pipelines/coreclr/templates/perf-job.yml
        eng/pipelines/coreclr/templates/*-perf-*
        eng/pipelines/coreclr/templates/run-perf*
        eng/pipelines/coreclr/templates/run-scenarios-job.yml
        eng/testing/performance/*
    ]

    # src/workloads is only used in runtime-official builds
    # where evaluate-paths is not used
    _always_exclude: [
        eng/pipelines/common/evaluate-default-paths.yml
        '*.md'
        LICENSE.TXT
        PATENTS.TXT
        THIRD-PARTY-NOTICES.TXT
        src/workloads/*
        src/mono/wasm/sln/*
    ]

jobs:
- template: /eng/pipelines/common/evaluate-paths-job.yml
  parameters:
    paths:
    - subset: coreclr
      include:
      - src/libraries/System.Private.CoreLib/*
      - src/native/libs/Common/*
      - src/native/libs/System.Globalization.Native/*
      - src/native/libs/System.IO.Compression.Native/*
      exclude:
      - eng/Version.Details.xml
      - docs/*
      - src/installer/*
      - src/mono/*
      - src/libraries/*
      - src/native/libs/*
      - src/tests/*
      - src/tools/*
      - eng/pipelines/installer/*
      - eng/pipelines/mono/*
      - eng/pipelines/libraries/*
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    - subset: mono_excluding_wasm
      include:
      - src/libraries/System.Private.CoreLib/*
      - src/native/libs/Common/*
      - src/native/libs/System.Globalization.Native/*
      - src/native/libs/System.IO.Compression.Native/*
      exclude:
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

      - eng/Version.Details.xml
      - docs/*
      - src/installer/*
      - src/coreclr/*
      - src/libraries/*
      - src/native/libs/*
      - src/tests/*
      - src/tools/*
      - eng/pipelines/installer/*
      - eng/pipelines/coreclr/*
      - eng/pipelines/libraries/*

    - subset: libraries
      exclude:
      - eng/Version.Details.xml
      - docs/*
      - src/installer/*
      - src/mono/*
      - src/coreclr/*
      - src/tests/*
      - src/tools/*
      - src/native/eventpipe/*
      - eng/pipelines/coreclr/*
      - eng/pipelines/mono/*
      - eng/pipelines/installer/*
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    - subset: runtimetests
      combined: true
      include:
      - src/tests/*
      exclude:
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    - subset: tools_illink
      include:
      - src/tools/illink/*
      - global.json

    - subset: installer
      include:
      exclude:
      - eng/Version.Details.xml
      - docs/*
      - src/coreclr/*
      - src/mono/*
      - src/libraries/*
      - src/tests/*
      - src/tools/*
      - src/native/eventpipe/*
      - eng/pipelines/coreclr/*
      - eng/pipelines/mono/*
      - eng/pipelines/libraries/*
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    # We have limited Apple Silicon testing capacity
    # We want PR testing on a narrower set of changes
    # Specifically runtime directories which are higher risk of
    # introducing a platform specific regression
    - subset: coreclr_AppleSilicon
      include:
      - src/coreclr/dlls/*
      - src/coreclr/gc/*
      - src/coreclr/gcinfo/*
      - src/coreclr/inc/*
      - src/coreclr/jit/*
      - src/coreclr/pal/*
      - src/coreclr/vm/*
    - subset: coreclr_jit
      include:
      - src/coreclr/jit/*

    #
    # ** WASM **
    # Changes in *only* Wasm.Build.Tests, debugger, or runtime-tests are very
    # self-contained, so we try to trigger only those relevants tests
    #
    - subset: wasmbuildtests
      combined: true
      include:
      - eng/Version.Details.xml
      - eng/Versions.props
      - eng/testing/scenarios/BuildWasiAppsJobsList.txt
      - eng/testing/scenarios/BuildWasmAppsJobsList.txt
      - eng/testing/tests.browser.targets
      - eng/testing/tests.was*.targets
      - src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/Sdk/WorkloadTesting.Core.targets
      - eng/testing/workloads-browser.targets
      - eng/testing/workloads-testing.targets
      - eng/testing/workloads-wasi.targets
      - eng/testing/workloads-wasm.targets
      - src/installer/pkg/sfx/Microsoft.NETCore.App/*
      - src/libraries/sendtohelix*
      - src/libraries/System.Net.WebSockets.Client/*
      - src/libraries/System.Runtime.InteropServices/*
      - src/libraries/System.Runtime.InteropServices.JavaScript/*
      - src/mono/mono/*
      - src/mono/mono.proj
      - src/mono/monoaotcross.proj
      - src/mono/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/*
      - src/mono/nuget/Microsoft.NET.Runtime.MonoTargets.Sdk/*
      - src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/*
      - src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/*
      - src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/*
      - src/mono/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/*
      - src/mono/nuget/Microsoft.NET.Workload*
      - src/mono/nuget/Microsoft.NETCore.BrowserDebugHost.Transport/*
      - src/mono/browser/build/*
      - src/mono/browser/emscripten-version.txt
      - src/mono/browser/runtime/*
      - src/mono/wasm/build/*
      - src/mono/wasm/host/*
      - src/mono/wasm/templates/*
      - src/mono/wasm/testassets/*
      - src/mono/wasm/Wasm.Build.Tests/*
      - src/mono/wasi/build/*
      - src/mono/wasi/runtime/*
      - src/mono/wasi/testassets/*
      - src/mono/wasi/Wasi.Build.Tests/*
      - ${{ parameters._const_paths._wasm_chrome }}
      - ${{ parameters._const_paths._wasm_src_native }}
      - src/tasks/*
      - ${{ parameters._const_paths._wasm_pipelines }}
      exclude:
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    - subset: wasmdebuggertests
      combined: true
      include:
      - ${{ parameters._const_paths._wasm_chrome }}
      - src/libraries/System.Runtime.InteropServices/*
      - src/libraries/System.Runtime.InteropServices.JavaScript/*
      - src/mono/mono/*
      - src/mono/browser/debugger/*
      - src/mono/browser/runtime/*
      - ${{ parameters._const_paths._wasm_src_native }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      exclude:
      - src/mono/nuget/*
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    # wasm/runtimetests need to be run
    - subset: wasm_runtimetests
      combined: true
      include:
      - src/tests/*
      - src/mono/*
      - ${{ parameters._const_paths._wasm_src_native }}
      exclude:
      - src/mono/nuget/*
      - src/mono/sample/*
      - src/mono/tests/*
      - src/mono/tools/*
      - src/mono/wasi/*
      - src/mono/wasm/debugger/*
      - src/mono/wasm/host/*
      - src/mono/wasm/templates/*
      - src/mono/wasm/testassets/*
      - src/mono/wasm/Wasm.Build.Tests/*
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    # Wasm except Wasm.build.Tests, Wasi.build.Tests and debugger
    - subset: wasm_specific_except_wbt_dbg
      combined: true
      include:
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      # other paths that should also trigger wasm jobs
      - src/mono/*
      exclude:
      - eng/testing/scenarios/BuildWasiAppsJobsList.txt
      - eng/testing/scenarios/BuildWasmAppsJobsList.txt
        src/mono/nuget/Microsoft.NET.Runtime.WorkloadTesting.Internal/Sdk/WorkloadTesting.Core.targets
      - eng/testing/workloads-browser.targets
      - eng/testing/workloads-testing.targets
      - eng/testing/workloads-wasi.targets
      - eng/testing/workloads-wasm.targets
      - src/mono/mono/component/mini-wasm-debugger.c
      - src/mono/browser/debugger/*
      - src/mono/wasm/host/*
      - src/mono/wasm/templates/*
      - src/mono/wasm/testassets/*
      - src/mono/wasm/Wasm.Build.Tests/*
      - src/mono/wasi/build/*
      - src/mono/wasi/runtime/*
      - src/mono/wasi/testassets/*
      - src/mono/wasi/Wasi.Build.Tests/*
      - src/mono/nuget/Microsoft.NET.Runtime*
        src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/*
      - src/mono/nuget/Microsoft.NET.Workload*
      - src/mono/nuget/Microsoft.NETCore.BrowserDebugHost.Transport/*
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}

    - subset: wasm_chrome
      include:
      - ${{ parameters._const_paths._wasm_chrome }}

    # anything other than mono, or wasm specific paths
    - subset: non_mono_and_wasm
      exclude:
      - eng/pipelines/mono/*
      - ${{ parameters._const_paths._wasm_specific_only }}
      - ${{ parameters._const_paths._wasm_pipelines }}
      - ${{ parameters._const_paths._always_exclude }}
      - ${{ parameters._const_paths._perf_pipeline_specific_only }}
      - eng/testing/tests.mobile.targets
      - src/mono/*
      - src/tasks/AndroidAppBuilder/*
      - src/tasks/AotCompilerTask/*
      - src/tasks/AppleAppBuilder/*
      - src/tasks/MonoTargetsTasks/*
      - src/tasks/WasmAppBuilder/*
      - src/tasks/WasmBuildTasks/*
      - src/tasks/WorkloadBuildTasks/*

    - ${{ if ne(parameters.extraSubsets, '') }}:
      - ${{ parameters.extraSubsets }}
